Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports System.Web
Imports System.Xml
Imports Subsonic
Imports ClubStarterKit.Data

Partial Class CommentsRss
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim BlogPost As String = Request("blogid").ToString()
        Dim BlogTitle As String = GetPostName(BlogPost)
        Response.Clear()
        Response.ContentType = "text/xml"
        Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        objX.WriteStartDocument()
        objX.WriteStartElement("rss")
        objX.WriteAttributeString("version", "2.0")
        objX.WriteStartElement("channel")
        objX.WriteElementString("title", ClubStarterKit.Web.Settings.Name() & ": Blog Post Comments (" & BlogTitle & ")")
        objX.WriteElementString("link", ClubStarterKit.Web.Settings.SiteURL() & "Blogs/post.aspx?id=" & BlogPost)
        objX.WriteElementString("description", "Blog Comments for " & BlogTitle)
        objX.WriteElementString("copyright", ClubStarterKit.Web.Settings.Copyright())
        objX.WriteElementString("ttl", "20")
        Dim qry As New Query(Tables.BlogComments)
        qry.QueryType = QueryType.Select
        qry.AddWhere(BlogComments.Columns.Postid, BlogPost)
        qry.SelectList = BlogComments.Columns.Name & "," & BlogComments.Columns.Comment & "," & BlogComments.Columns.Postid
        qry.OrderBy = OrderBy.Asc(BlogComments.Columns.Commentid)
        Dim objReader As SqlDataReader = qry.ExecuteReader()
        While objReader.Read()
            objX.WriteStartElement("item")
            objX.WriteElementString("title", objReader.GetString(0))
            objX.WriteElementString("description", objReader.GetString(1))
            objX.WriteElementString("link", ClubStarterKit.Web.Settings.SiteURL() & "blogs/post.aspx?id=" & objReader.GetInt32(2))
            objX.WriteElementString("author", objReader.GetString(1))
            objX.WriteEndElement()
        End While
        objReader.Close()
        objX.WriteEndElement()
        objX.WriteEndElement()
        objX.WriteEndDocument()
        objX.Flush()
        objX.Close()
        Response.End()
    End Sub

    Private Function GetPostName(ByVal postid As String) As String
        Dim BlogPosts As New BlogPosts(BlogPosts.Columns.Postid, postid)
        If BlogPosts.IsLoaded = True Then
            Return BlogPosts.Title
        Else
            Return ""
        End If
    End Function
End Class
